<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>文件管理</title>
     <link href="css/uploadify.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="js/swfobject.js"></script>
    <script type="text/javascript" src="js/jquery.uploadify.js"></script>
    <script type="text/javascript">
    <!--
    $(document).ready(function(){
    	var userid = $("#userid").val();
    	$.ajax({
    		type: 'post',
    		url: 'listAllFiles.action',
    		data: {userid: userid},
    		dataType: 'xml',
    		success: function(xml){
    			var result="<table border='1px'>";
    			result += "<tr><th>文件名</th><th>上传时间</th><th>状态</th><th>&nbsp;</th></tr>";
    			$(xml).find("file").each(function(){
    				result += "<tr>";
    				result += "<td><a href='"+$(this).children("url").text()+"'>"+$(this).children("name").text()+"</a></td>";
    				result += "<td>"+$(this).children("date").text()+"</td>";
    				if($(this).children("isshared").text() == 1){
    					result += "<td>公开</td>";
    					result += "<td><input fileid='"+$(this).children("id").text()+"' type='button' class='hideFile' value='自己可见' style='width:65px'/> <input fileid='"+$(this).children("id").text()+"' type='button' class='deleteFile' value='删除'/></td>";
    				}
    				else{
    					result +="<td>私有</td>";
    					result += "<td><input fileid='"+$(this).children("id").text()+"' type='button' class='showFile' value='分享' style='width:65px'/> <input fileid='"+$(this).children("id").text()+"' type='button' class='deleteFile' value='删除'/></td>";
    				}
    				
    				result += "</tr>";
    				
    			});
    			result += "</table>";
    			$("#myFilesDiv").html(result);
    		}
    	});
    	
    	$(".hideFile").live("click",function(){
    		$.ajax({
    			type: 'post',
    			url: 'hideFile.action',
    			data: {fileId: $(this).attr("fileid")},
    			success: function(){
    				var userid = $("#userid").val();
    		    	$.ajax({
    		    		type: 'post',
    		    		url: 'listAllFiles.action',
    		    		data: {userid: userid},
    		    		dataType: 'xml',
    		    		success: function(xml){
    		    			var result="<table border='1px'>";
    		    			result += "<tr><th>文件名</th><th>上传时间</th><th>状态</th><th>&nbsp;</th></tr>";
    		    			$(xml).find("file").each(function(){
    		    				result += "<tr>";
    		    				result += "<td><a href='"+$(this).children("url").text()+"'>"+$(this).children("name").text()+"</a></td>";
    		    				result += "<td>"+$(this).children("date").text()+"</td>";
    		    				if($(this).children("isshared").text() == 1){
    		    					result += "<td>公开</td>";
    		    					result += "<td><input fileid='"+$(this).children("id").text()+"' type='button' class='hideFile' value='自己可见' style='width:65px'/> <input fileid='"+$(this).children("id").text()+"' type='button' class='deleteFile' value='删除'/></td>";
    		    				}
    		    				else{
    		    					result +="<td>私有</td>";
    		    					result += "<td><input fileid='"+$(this).children("id").text()+"' type='button' class='showFile' value='分享' style='width:65px'/> <input fileid='"+$(this).children("id").text()+"' type='button' class='deleteFile' value='删除'/></td>";
    		    				}
    		    				
    		    				result += "</tr>";
    		    				
    		    			});
    		    			result += "</table>";
    		    			$("#myFilesDiv").html(result);
    		    		}
    		    	});
    			}
    		});
    	});
    	
    	$(".showFile").live("click",function(){
    		$.ajax({
    			type: 'post',
    			url: 'showFile.action',
    			data: {fileId: $(this).attr("fileid")},
    			success: function(){
    				var userid = $("#userid").val();
    		    	$.ajax({
    		    		type: 'post',
    		    		url: 'listAllFiles.action',
    		    		data: {userid: userid},
    		    		dataType: 'xml',
    		    		success: function(xml){
    		    			var result="<table border='1px'>";
    		    			result += "<tr><th>文件名</th><th>上传时间</th><th>状态</th><th>&nbsp;</th></tr>";
    		    			$(xml).find("file").each(function(){
    		    				result += "<tr>";
    		    				result += "<td><a href='"+$(this).children("url").text()+"'>"+$(this).children("name").text()+"</a></td>";
    		    				result += "<td>"+$(this).children("date").text()+"</td>";
    		    				if($(this).children("isshared").text() == 1){
    		    					result += "<td>公开</td>";
    		    					result += "<td><input fileid='"+$(this).children("id").text()+"' type='button' class='hideFile' value='自己可见' style='width:65px'/> <input fileid='"+$(this).children("id").text()+"' type='button' class='deleteFile' value='删除'/></td>";
    		    				}
    		    				else{
    		    					result +="<td>私有</td>";
    		    					result += "<td><input fileid='"+$(this).children("id").text()+"' type='button' class='showFile' value='分享' style='width:65px'/> <input fileid='"+$(this).children("id").text()+"' type='button' class='deleteFile' value='删除'/></td>";
    		    				}
    		    				
    		    				result += "</tr>";
    		    				
    		    			});
    		    			result += "</table>";
    		    			$("#myFilesDiv").html(result);
    		    		}
    		    	});
    			}
    		});
    	});
    	
    	$(".deleteFile").live("click",function(){
    		$.ajax({
    			type: 'post',
    			url: 'deleteFile.action',
    			data: {fileId: $(this).attr("fileid")},
    			success: function(){
    				var userid = $("#userid").val();
    		    	$.ajax({
    		    		type: 'post',
    		    		url: 'listAllFiles.action',
    		    		data: {userid: userid},
    		    		dataType: 'xml',
    		    		success: function(xml){
    		    			var result="<table border='1px'>";
    		    			result += "<tr><th>文件名</th><th>上传时间</th><th>状态</th><th>&nbsp;</th></tr>";
    		    			$(xml).find("file").each(function(){
    		    				result += "<tr>";
    		    				result += "<td><a href='"+$(this).children("url").text()+"'>"+$(this).children("name").text()+"</a></td>";
    		    				result += "<td>"+$(this).children("date").text()+"</td>";
    		    				if($(this).children("isshared").text() == 1){
    		    					result += "<td>公开</td>";
    		    					result += "<td><input fileid='"+$(this).children("id").text()+"' type='button' class='hideFile' value='自己可见' style='width:65px'/> <input fileid='"+$(this).children("id").text()+"' type='button' class='deleteFile' value='删除'/></td>";
    		    				}
    		    				else{
    		    					result +="<td>私有</td>";
    		    					result += "<td><input fileid='"+$(this).children("id").text()+"' type='button' class='showFile' value='分享' style='width:65px'/> <input fileid='"+$(this).children("id").text()+"' type='button' class='deleteFile' value='删除'/></td>";
    		    				}
    		    				
    		    				result += "</tr>";
    		    				
    		    			});
    		    			result += "</table>";
    		    			$("#myFilesDiv").html(result);
    		    		}
    		    	});
    			}
    		});
    	});
    	
    	 $("#uploadify").uploadify({
         	'swf'         : 'uploadify.swf',
             'uploader'       : 'Upload',
             'folder'         : 'uploads',
             'queueID'        : 'fileQueue',
             'auto'           : false,
             'multi'          : true,
             'simUploadLimit' : 2,
             'buttonText'     : '选择文件',
             'onUploadSuccess' : function(file, data, response) {
            	 $.ajax({
     	    		type: 'post',
     	    		url: 'listAllFiles.action',
     	    		data: {userid: userid},
     	    		dataType: 'xml',
     	    		success: function(xml){
     	    			var result="<table border='1px'>";
     	    			result += "<tr><th>文件名</th><th>上传时间</th><th>状态</th><th>&nbsp;</th></tr>";
     	    			$(xml).find("file").each(function(){
     	    				result += "<tr>";
     	    				result += "<td><a href='"+$(this).children("url").text()+"'>"+$(this).children("name").text()+"</a></td>";
     	    				result += "<td>"+$(this).children("date").text()+"</td>";
     	    				if($(this).children("isshared").text() == 1){
     	    					result += "<td>公开</td>";
     	    					result += "<td><input fileid='"+$(this).children("id").text()+"' type='button' class='hideFile' value='自己可见' style='width:65px'/> <input fileid='"+$(this).children("id").text()+"' type='button' class='deleteFile' value='删除'/></td>";
     	    				}
     	    				else{
     	    					result +="<td>私有</td>";
     	    					result += "<td><input fileid='"+$(this).children("id").text()+"' type='button' class='showFile' value='分享' style='width:65px'/> <input fileid='"+$(this).children("id").text()+"' type='button' class='deleteFile' value='删除'/></td>";
     	    				}
     	    				
     	    				result += "</tr>";
     	    				
     	    			});
     	    			result += "</table>";
     	    			$("#myFilesDiv").html(result);
     	    		}
     	    	});
             }
         });
    	 
    	
    });
    //-->
    </script>
 
    <link href="images/skin.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
	body{
		margin:0;
		padding:0;
	}
	#top{
		width: 100%;
		height: 63px;
	}
	#left{
		position: absolute;
		left: 0;
		top: 65px;
		width:185px;

	}
	#right{
		position: absolute;
		left: 186px;
		top: 65px;
		width: 1100px;
	}
	</style>
  </head>
  
  
  <body>
  
	
	<div id="top"><jsp:include page="/WEB-INF/page/top.jsp"></jsp:include></div>
	<div id="left"><jsp:include page="/WEB-INF/page/lef.jsp"></jsp:include></div>
	<div id="right">
	
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">文件列表</div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="2" valign="top">&nbsp;</td>
        <td>&nbsp;</td>
        <td valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2" valign="top"><span class="left_bt"></span><br/>
			<input type="hidden" id="userid" value="${userid }"/>
    <div id="myFilesDiv">
    </div>
    <br/><br/>
    <div id="fileQueue"></div>
        <input type="file" name="uploadify" id="uploadify" />
        <p>
        <a href="javascript: jQuery('#uploadify').uploadify('upload','*');" >开始上传</a>&nbsp;
        <a href="javascript:jQuery('#uploadify').uploadify('cancel','*')">取消所有上传</a>
        </p>
        <a href="goMain.action">返回</a>
    
        </td>
          </tr>
	</div>
  
  </body>
</html>

